Unsolved Work with table
-
Hi everybody! So, I have next table:
Unfortunallety, I don't have experience of using QTableWidget, but I need work with him. So, I have some problems:- I set style of
'QTableWidget'
with setStyleSheet, and items style set in the same way. But when I try edit cells, style of cells in editing change on style of mainwindow. I try create custom Delegate, but not good understand, how can change style in it. Besides I need check value in cells, when user input data. All data in cells - it's a hexadecimal numbers. I want to check, that user input value < FF and > 0. Otherwise, issue a warning and offer to enter the number again. - How can I call editor not double-click mouse but by clicking on pushButton or pressing a button on the keyboard? And the same way close the editor and save data.
I'm sorry for so big question, but I try understand this for two weeks and while unsuccess. I hope you will be able to help me. Thanks!
- I set style of
-
@Vlad02 said in Work with table:
I set style of 'QTableWidget' with setStyleSheet, and items style set in the same way. But when I try edit cells, style of cells in editing change on style of mainwindow.
What does your stylesheet look like? There are different options and styles for selected/edited rows/cols.
-
@Pl45m4 My StyleSheet:
QString StyleHelper::getMemoryStyle() { return "QTableWidget{" " border-left: 2px solid #555555;" " border-top: 2px solid #555555;" " border-right: 2px solid white;" " border-bottom: 2px solid white;" " background-color: black;" "}" "QTableWidget::item{" " background-color: black;" " border: 2px solid #555555;" " font-family: Undertale Battle Font;" " font-size: 14px;" "}" "QTableWidget::item:selected{" " background-color: red;" "}"; }
-
Hi,
For the delegate, the best is to not allow for invalid values to be entered in the first place. Use an hexadecimal spinbox.
You have an example implementation in this stack overflow thread.
-
@SGaist Is it possible to not use a delegate? Or without it?
-
What is the issue in using a delegate to provide a custom editor ?
-
@SGaist Rather, I don't really like the option with a spinbox. Will I be able to load data from a text file into such cells?
-
@Vlad02
What about a QLineEdit with an input mask/validator:
https://stackoverflow.com/questions/47517925/validate-text-in-qtablewidget -
@mpergand
Hm, this looks interesting. I will study this question, look for ways to do it in c++. Thank you! -
@Vlad02 said in Work with table:
@SGaist Rather, I don't really like the option with a spinbox. Will I be able to load data from a text file into such cells?
This is just an editor, it has nothing to do with how you load the data from your text file into the model.
You can write values as well into a spin box so from that point of view, it's a specialised QLineEdit that handles numerical values and in this case, A to F as well with the added benefit that users can use the controls or their arrow keys to increment/decrement the value. -
@mpergand
Thank you again, using a mask allowed me to get rid of the need to validate user input