Results 1 to 5 of 5

Thread: How to change empty editor color?

  1. #1
    Join Date
    Jan 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default How to change empty editor color?

    Qt Code:
    1. MainWindow::MainWindow() {
    2. createMenus();
    3. tabWidget = new QTabWidget;
    4. edit = new CodeEditor();
    5. //tabWidget->addTab(edit, "1");
    6. setCentralWidget(tabWidget);
    7. }
    To copy to clipboard, switch view to plain text mode 
    If I write "tabWidget->add", is OK, one tab.
    If not, is empty editor. Its color is white, I prefer gray and don't know, I must change MainWindow background color or empty QTabWidget background color (which is central widget)

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,140
    Thanks
    294
    Thanked 852 Times in 839 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to change empty editor color?

    Retrieve the QPalette for the QTabWidget after it is created, set the QPalette::Window color to whatever you want, then set it back on the QTabWidget:

    Qt Code:
    1. tabWidget = new QTabWidget( this );
    2. QPalette pal = tabWidget->palette();
    3. pal.setColor( QPalette::Window, QColor( "gray" ) );
    4. tabWidget->setPalette( pal );
    To copy to clipboard, switch view to plain text mode 
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jan 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to change empty editor color?

    I changed all to red, but still is white,...
    Qt Code:
    1. QPalette pal = tabWidget->palette();
    2. for (int i=0; i<QPalette::NColorRoles; i++) {
    3. pal.setColor(QPalette::ColorRole(i), QColor("red"));
    4. }
    5. tabWidget->setPalette(pal);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,140
    Thanks
    294
    Thanked 852 Times in 839 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to change empty editor color?

    I changed all to red, but still is white,...
    Then I guess there is something in the QTabWidget painting code that ignores the palette. The QTabWidget is a compound widget - it consists of a QTabBar and a QStackedWidget that holds the widget for each tab. The tab bar interacts with the stacked widget to change which widget is on top. The stacked widget is not accessible through the QTabWidget API, so it is not possible to set its palette directly.

    The only workaround I can think of is to create a tab with an empty QWidget and set the Window color for that. When you are ready to add a real widget (your CodeEditor, for example), add a new tab and then delete the empty one.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Dec 2011
    Posts
    59
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to change empty editor color?

    As d_stranz mentioned, you probably need to loop through all the child widgets.

    "mainWidget" here can be anything, either your main window, in which case this code will color all child widgets in your app (this is how you create a "color theme"), or it can be your QTabWidget, in which case it should solve your problem.

    Qt Code:
    1. // Loop through all child widgets of the main widget and apply the color settings
    2. QList<QWidget*> widgets = mainWidget->findChildren<QWidget*>();
    3. foreach (QWidget* w, widgets)
    4. {
    5. w->setPalette(p);
    6. w->update();
    7. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 0
    Last Post: 2nd December 2020, 16:06
  2. Color Editor Factory Documentation
    By alitoh in forum Newbie
    Replies: 5
    Last Post: 9th May 2011, 20:25
  3. Text editor color scheme
    By kosasker in forum Qt Tools
    Replies: 4
    Last Post: 14th February 2011, 21:36
  4. Replies: 3
    Last Post: 22nd January 2010, 16:46
  5. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 22:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.