I am trying to modify the QTableView to always show all editors. I am ok with the workaround to call openPersistentEditor() on all cells.
However I'd like the content of the cells to not be selected and no text cursor for empty fields.
This is what I get:
And this is what I'd like to have:
I tried using clearSelection() and clearFocus() but that does not do the trick. If I click on each cell I get the desired result and I could do the same thing programmatically, but I'd to know if there's a more direct way.
I had this exact same issue. I ended up just adjusting the selection color and selection background color on the QLineEdits. You can do it on all QLineEdits or just on a custom QLineEdit by giving each editor an object name and referencing that in the stylesheet.
/* applies to all QLineEdits in the application */
QLineEdit {
selection-background-color: white;
selection-color: black
}
/* applies to all QLineEdits with the object name "custom" in the application */
QLineEdit#custom {
selection-background-color: white;
selection-color: black
}
Related
I wrote a minimal example which has a sidebar which contains a QToolButton on it. I set setAutoRaise(true) for the QToolButton, so when hover on it, the button will raise. But currently I have a minor issue. As you can see from the picture below, when hover on the button, the border on the right and left are not fully take the whole screen.
Here is how that looks like:
And this example what I want to button to look like:
And here is my code:
sidebarDock = new QDockWidget(this);
addDockWidget(Qt::LeftDockWidgetArea, sidebarDock);
//hide dock widget title bar
QWidget *titleBarWidget = new QWidget(sidebarDock);
sidebarDock->setTitleBarWidget(titleBarWidget);
sidebarDock->titleBarWidget()->hide();
dockWidget = new QWidget(sidebarDock);
dockWidget->setObjectName("DockWidget");
dockWidget->setStyleSheet("#DockWidget { background-color: #F7DC6F; }");
dockVLayout = new QVBoxLayout(dockWidget);
overviewBtn = new QToolButton(dockWidget);
overviewBtn->setAutoRaise(true);
overviewBtn->setIcon(QIcon(":/Icons/overview.png"));
overviewBtn->setText("Overview");
overviewBtn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
dockVLayout->addWidget(overviewBtn);
dockWidget->setLayout(dockVLayout);
sidebarDock->setWidget(dockWidget);
So can someone tell me which part I missed to set the QQToolButton right and left border completely to side? Or are there some better ways to achieve this? Thanks.
Now I solved this problem.
Just need to add one line to the code snippet to set the layout's margin to 0, using: dockVLayout->setMargin(0)
I have a QTabWidget with two tabs inside. I want to set the background of both tabs to be transparent to see the color of the main window underneath, but when I set
QTabWidget *tabWidget = new QTabWidget(this);
tabWidget-setStyleSheet("background-color: transparent;");
it makes all the background of the widgets I have inside the tabs transparent, not the tab itself.
Album showing before stylesheet change:
after change,
and what I'm trying to achieve.
I can provide more code if needed. Thanks in advance!
Stylesheets are applied to touched widgets and all its children.
Currently your style definitions
QTabWidget *tabWidget = new QTabWidget(this);
tabWidget-setStyleSheet("background-color: transparent;");
says something like "Set background color for all widgets to transparent".
... but you can restrict stylesheet applicability.
E.g. you can say, that style definitions should be applied only to instances of certain classes like QLabel:
QTabWidget *tabWidget = new QTabWidget(this);
tabWidget-setStyleSheet("QLabel{ background-color: transparent; }");
There are even more possibilietes to define applicability in more details:
The Qt Style Sheet Syntax, Selector Types
Relevant for your case is the possibility to restrict the applicability of style definitions to objects with certain name:
QTabWidget *tabWidget = new QTabWidget(this);
tabWidget-setStyleSheet("QWidget#custom_tab, QWidget#templates_tab{"
" background-color: transparent; "
"}");
You must make sure, that object names match (here: 'custom_tab' and 'templates_tab'.
I'm working on a software which contains combobox with a lot of items inside, the problem is when I click on it the list is too large and I can't see all of the items by scrolling on it.
The style cleanlooks is used (that's why the combobox have a too large size) but I can't change it so I'm looking for a solution to set a maximum size.
I found nothing about this on the web, neither in the documentation.
I tried to use the size policy but doesn't work. I also tried to get the QLineEdit used by the combobox and to set a QSize on it and finally to by setting stylesheet on the combobox and on the QLineEdit but nothing worked properly.
What I tried with the QSize and the stylesheet :
sz = QSize(20, 20)
combo.view().setGridSize(sz)
combo.view().setStyleSheet("""QListView { max-height: 50px; background-color: yellow; } """)
combo.setStyleSheet("""QComboBox { max-height: 30px; background-color: pink; } """)
EDIT: After the comment of #Vladimir Bershov I tried to set correctly the size with : setMaxVisibleItems() but as said in the doc ("Note: This property is ignored for non-editable comboboxes in styles that returns true for QStyle::SH_ComboBox_Popup") the property is ignored.
So I looked for modify the QStyle Hint to unset the SH_ComboBox_Popup but as explained on this post that's impossible.
If you have any suggestions I'm listening.
Thanks.
Like explained in the comments there's no available solutions in PyQt4
This line worked for me when I was trying to minimize the height of the QComboBox dropdown in Qt/C++.
ComboBox->setStyleSheet("combobox-popup: 0;");
I am attempting to add a fade-in/fade-out effect to a widget (that contains other widgets, including buttons and text fields).
The problem is that while buttons fade perfectly, text fields do not - instead of changing opacity of the text field, only the opacity of its border changes.If the text has been selected before changing opacity, after the opacity is reduced, the selection looks strange.
What can be the cause of this problem and how to make the fade effect on all widgets, not only push buttons?
The problem can be easily reproduced, if you place a QTextField on form, and add the following code to button handlers:
void MainWindow::on_pushButton_3_clicked()
{
QGraphicsOpacityEffect * effect = new QGraphicsOpacityEffect(ui->plainTextEdit);
effect->setOpacity(0.1);
ui->plainTextEdit->setGraphicsEffect(effect);
}
After this code is run, you will see something like this:
Image1
void MainWindow::on_pushButton_4_clicked()
{
QGraphicsOpacityEffect * effect = new QGraphicsOpacityEffect(ui->plainTextEdit);
effect->setOpacity(1.0);
ui->plainTextEdit->setGraphicsEffect(effect);
}
The text field looks like this, after this method is executed:
Image2
Thanks.
In my qt C++ gui application, I have a QMessageBox with 3 buttons and some standard functionality. I want to decorate all these with stylesheets and fonts and what not.
I am successfully able to do the following -
i. Set MessageBox background.
ii. Set Button background.
void MainWindow::on_pushButton_clicked()
{
QMessageBox msgbox;
msgbox.setInformativeText("YOLO");
msgbox.setStandardButtons(QMessageBox::Ok|QMessageBox::No|QMessageBox::Cancel);
msgbox.setWindowFlags(Qt::FramelessWindowHint);
msgbox.setStyleSheet("QMessageBox { background-image: url(:/res/bk.jpg) }");
msgbox.button(QMessageBox::Ok)->setStyleSheet("QPushButton { background-image: url(:/res/green_bk.jpg) }");
msgbox.button(QMessageBox::No)->setStyleSheet("QPushButton { background-image: url(:/res/red_bk.jpeg) }");
msgbox.exec();
}
But I am stuck on how to set a font (type and size) to the InformativeText field, and also how to make it Bold. I have referred to the InformativeText Properties but I am unable to sort things out. Any ideas on how to achieve this ? Thanks.
As an added query, can I change the fonts (type and size) of buttons as well and set Bold Italics etc ?
EDIT
I did the following changes to my code, and the results are baffling,
QFont font;
font.setBold(true);
msgbox.setFont(font);
After doing this, my informationText has become bold, my cancel button has become bold. But the Ok and No buttons are normal (non-bold). If I remove the setStylesheets for the two buttons, only then are they becoming bold (which is useless, since I want background images).
Any ideas to have a synergy in all these ???
I found solution for your problems.
QMessageBox msg(QMessageBox::Information,"Hey", "Dude", QMessageBox::Ok);
QFont font;
font.setBold(true);
msg.setFont(font);
msg.button(QMessageBox::Ok)->setFont(font);
msg.exec();