Using multiple QSyntaxHighlighter in one QPlainTextEdit

I have written two syntax highlighter: one for CSS and one for HTML. They work well.

But, I want to color CSS code in HTML code (inside <style> tag), so I want to be able to use multiple QSyntaxHighlighter in one QPlainTextEdit.

Is there a way to do what I want? I cannot instantiate two QSyntaxHighlighter objects on the same QPlainTextEdit because only the second object will be used.

Thanks.

-------------Problems Reply------------

You'll need to handle switching between the different highlighting modes yourself, within a single syntax highlighter.

I'd start with your HTML highlighter, since it should be able to tell when you're inside a <style> tag. Use the setCurrentBlockState to mark that block as CSS, and delegate to the CSS renderer.

The basic idea is illustrated in the QSyntaxHighlighter docs (switching between comment/code modes) and the example.

Category:qt Views:1 Time:2011-09-16

Related post

  • Disable 'Return' key in a QPlainTextEdit 2010-08-09

    Is there any way I can prevent the user from hitting the return key when entering text in a QPlainTextEdit widget? That is, even though I want to give the viewing space of multiple lines, I want that the if the user hits enter, a new line should not

  • How to paginate a QPlainTextEdit? 2010-08-31

    I've been using QPlainTextEdit for editing text in our application. Recently it was decided that we need to display the text in a paginated format instead of a consistent block of text. After lots of research, I've come to the realization that while

  • Find all strings wanted and select them with QPlainTextEdit::setExtraSelections() 2011-10-02

    I'm trying to highlight all strings find in a QPlainTextEdit widget , but find() will only return the first result. The following code isn't working out , why ? (textview is a class derivated from QPlainTextEdit) And please don't ask me to use QSynta

  • How do I get rid of the "multiple describeType entries" warning? 2008-08-08

    Does anyone know why when using BindingUtils on the selectedItem property of a ComboBox you get the following warning? Any ideas how to resolve the issue? The binding still works properly, but it would be nice to get rid of the warning. warning: mult

  • Programatically select multiple files in windows explorer 2008-08-13

    I can display and select a single file in windows explorer like this: explorer.exe /select, "c:\path\to\file.txt" However, I can't work out how to select more than one file. None of the permutations of select I've tried work. Help! Note: I looked at

  • Actual Productivity Gains from Multiple Monitors 2008-08-13

    I see a lot of posts from people talking about how they cannot possibly live without two, three or 13 1/2 monitors but does anybody have an actual metrics or statistics which I could use as ammunition? Same question for comfortable chairs. The compan

  • Need Pattern for dynamic search of multiple sql tables 2008-08-13

    I'm looking for a pattern for performing a dynamic search on multiple tables. I have no control over the legacy (and poorly designed) database table structure. Consider a scenario similar to a resume search where a user may want to perform a search a

  • Subversion revision number across multiple projects 2008-08-19

    When using Subversion (svn) for source control with multiple projects I've noticed that the revision number increases across all of my projects' directories. To illustrate my svn layout (using fictitious project names): /NinjaProg/branches /tags /tru

  • How do you configure VS2008 to only open one webserver in a solution with multiple projects? 2008-08-19

    Starting with 2005, VS started this behavior of when starting debugging session it spawns up a webserver for every project in a solution. I have a solution with 15 projects so it takes a while and is a waste of resources. Is there a way to configure

  • Delete Datalist row with multiple primary keys 2008-08-21

    I have a datalist with a OnDeleteCommand="Delete_Command". I want the delete a record with multiple primary Keys but I do not know how to access it from the Delete_Command event. If I use DataKeyField I'm limited to only one key. Any workarounds for

  • SQL2005: Linking a table to multiple tables and retaining Ref Integrity? 2008-08-21

    Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote Fields: ID, PropertyID, BespokeQuoteFields... Table: Job Fields: ID, PropertyID, BespokeJobFields... Then we have other tables that relate to the Quote and Job

  • Display rows in multiple columns in Asp.net Gridview 2008-08-21

    By default each row of a Gridview maps to each row in a datatable or dataset attached to its datasource. But what if I want to display these rows in multiple columns. For example if it has 10 rows, 5 rows each should be displayed in 2 columns side by

  • SQL Query Help - Scoring Multiple Choice Tests 2008-08-22

    Say I have a Student table, it's got an int ID. I have a fixed set of 10 multiple choice questions with 5 possible answers. I have a normalized answer table that has the question id, the Student.answer (1-5) and the Student.ID I'm trying to write a s

  • Why is it bad practice to make multiple database connections in one request? 2008-08-26

    A discussion about Singletons in PHP has me thinking about this issue more and more. Most people instruct that you shouldn't make a bunch of DB connections in one request, and I'm just curious as to what your reasoning is. My first thought is the exp

  • How to determine if an html tag splits across multiple lines 2008-08-29

    I'm writing a php script that involves scraping web pages. Currently, the script analyzes the page line by line, but it breaks if there is a tag that spans multiple lines, like <img src="example.jpg" alt="example"> If worse comes to worse, I co

  • Multiple web-sites running in IIS simulatenously 2008-08-29

    At work, we have multiple branches that we may be working on at any time. Our solution so far as been to create multiple web-sites but you can only run one web-site at a time. This makes switching between branches more of a pain that in should be. I

  • File database suggestion with support for multiple concurent users 2008-08-29

    I need a database that could be stored network drive and would allow multiple users (up to 20) to use it without any server software. I'm considering MS Access or Berkeley DB. Can you share your experience with file databases? Which one did you use,

  • Managing multiple identical databases efficiently? 2008-08-29

    In Podcast #19, Joel fails to answer the question posed to him by Ryan from San Diego; how, if you have a database per client of a web application instead of one database used by all clients, do you "go about providing updates and enhancements to all

  • How do you combine multiple result sets in SSRS? 2008-08-29

    What's the best way to combine results sets from disparate data sources in SSRS? In my particular example, I need to write a report that pulls data from SQL Server and combines it with another set of data that comes from a DB2 database. In the end, I

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.160 (s). 11 q(s)