Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to disable focus border and background it QTreeWidget with fusion style?

How to disable focus border and background it QTreeWidget with fusion style?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    flammmable
    wrote on last edited by
    #1

    How to disable focus border and background it QTreeWidget with fusion style? The focus is wery annoying. Especially when I use alternating raw color.

    alt text

    #include <QApplication>
    #include <QWidget>
    #include <QTreeWidget>
    #include <QMessageBox>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        a.setStyle("fusion");
    
        QWidget *mainWidget = new QWidget();
        mainWidget->resize(200,150);
    
        QTreeWidget *myTree = new QTreeWidget(mainWidget);
        myTree->resize(200,150);
    
        QTreeWidgetItem *item;
        item = new QTreeWidgetItem(myTree);
        item->setText(0,"item1");
        //...
        item = new QTreeWidgetItem(myTree);
        item->setText(0,"item6");
    
        myTree->setAlternatingRowColors(true);
        myTree->setStyleSheet("QTreeView {background-color: #222222;"
                              "           alternate-background-color: #333333;"
                              "           selection-background-color: #FF77FF;}");
    
        myTree->setFocus();
        item->setSelected(true);
    
        mainWidget->show();
        return a.exec();
    }
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Often a delegate is used.
      https://stackoverflow.com/questions/2035049/qtreewidget-turn-off-selection

      1 Reply Last reply
      1
      • F Offline
        F Offline
        flammmable
        wrote on last edited by flammmable
        #3

        Thank you! This code

        setFocusPolicy(Qt::NoFocus);
        

        in the constructor of myTreeWidget helped me.

        mrjjM 1 Reply Last reply
        1
        • F flammmable

          Thank you! This code

          setFocusPolicy(Qt::NoFocus);
          

          in the constructor of myTreeWidget helped me.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @flammmable
          Ok. super. sorry forgot to mention :)

          1 Reply Last reply
          0
          • F Offline
            F Offline
            flammmable
            wrote on last edited by
            #5

            @mrjj NP ;)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved