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?
Forum Updated to NodeBB v4.3 + New Features

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.6k Views 1 Watching
  • 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 25 Apr 2019, 12:48 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 25 Apr 2019, 12:55 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 25 Apr 2019, 13:40 last edited by flammmable
        #3

        Thank you! This code

        setFocusPolicy(Qt::NoFocus);
        

        in the constructor of myTreeWidget helped me.

        M 1 Reply Last reply 25 Apr 2019, 13:41
        1
        • F flammmable
          25 Apr 2019, 13:40

          Thank you! This code

          setFocusPolicy(Qt::NoFocus);
          

          in the constructor of myTreeWidget helped me.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 25 Apr 2019, 13:41 last edited by
          #4

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

          1 Reply Last reply
          0
          • F Offline
            F Offline
            flammmable
            wrote on 25 Apr 2019, 13:43 last edited by
            #5

            @mrjj NP ;)

            1 Reply Last reply
            0

            4/5

            25 Apr 2019, 13:41

            • Login

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