Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.6k Topics 457.6k Posts
  • This topic is deleted!

    Unsolved
    1
    -1 Votes
    1 Posts
    3 Views
    No one has replied
  • Subclassing QAbstractTableModel

    Solved
    9
    0 Votes
    9 Posts
    3k Views
    S
    @JKSH Thank you very much for the help these past few days! As a conclusion to this thread, for anyone who may stumble upon it in the future, the working code: tablemodelcalss.h #ifndef TABLEMODELCLASS_H #define TABLEMODELCLASS_H #include <QAbstractTableModel> #include <QObject> #include <Eigen> #include <cassert> class TableModelClass : public QAbstractTableModel { Q_OBJECT public: TableModelClass(QObject *parent = 0); void Input(Eigen::MatrixXd InMat); int rowCount(const QModelIndex &parent) const override; int columnCount(const QModelIndex &parent) const override; QVariant data(const QModelIndex &index, int role) const override; private: Eigen::MatrixXd m_matrix; }; #endif // TABLEMODELCLASS_H tablemodleclass.cpp #include "tablemodelclass.h" #include <QDebug> TableModelClass::TableModelClass(QObject *parent) : QAbstractTableModel(parent) { } void TableModelClass::Input(Eigen::MatrixXd InMat) { beginResetModel(); m_matrix.resize(InMat.rows(), InMat.cols()); m_matrix = InMat; endResetModel(); } int TableModelClass::rowCount(const QModelIndex &parent) const { if(parent.isValid()) { return 0; } return m_matrix.rows(); } int TableModelClass::columnCount(const QModelIndex &parent) const { if(parent.isValid()) { return 0; } return m_matrix.cols(); } QVariant TableModelClass::data(const QModelIndex &index, int role) const { if(!index.isValid()) { return QVariant(); } if(index.row() >= (m_matrix.rows()) || index.row() < 0) { return QVariant(); } if(role == Qt::DisplayRole) { return m_matrix(index.row(), index.column()); } return QVariant(); }
  • Check state QListWidget

    Solved
    31
    0 Votes
    31 Posts
    4k Views
    JonBJ
    @naax Blocking signals is hiding whatever your issue is. You ought to sort out why your setFlags() is causing a problem in the first place, even if you then decide this is the simplest solution. If the fault is not elsewhere in your code. (You really ought check it out in a debugger.) I suppose it is possible that because you are doing this inside a slot, which is called because the the item is user-checkable and has been clicked, switching off ItemIsUserCheckable might cause a problem to Qt infrastructure code? If it were me I would try moving it out to a timer event or queued connection to establish where the problem is. Thought: QObject::connect(ui->listWidget, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(highlightChecked(QListWidgetItem*))); The code for changing the checkable state is being executed inside your connected highlightChecked slot? If setting the flags raises itemChanged signal you would have recursion till crash? Again, debugger would tell you, or even qDebug() statements.
  • Qt3, ColorDialog, and SLOT

    Unsolved
    11
    0 Votes
    11 Posts
    1k Views
    Pl45m4P
    @Ray-V said in Qt3, ColorDialog, and SLOT: what do I actually type in for 'someOtherObject'? Your button instance. Do you want to repaint one or multiple buttons? If you have only one, you can put your button instance (the pointer to your button) instead of this in your insertItem function. Then, if you have your W2 slot in your button class, it will run from there, so you can change the button's background directly.
  • How to know when inputMethod is cancelled?

    Unsolved
    2
    0 Votes
    2 Posts
    238 Views
    T
    After some though I realized this could also be a bug in mozc. I setup Anthy and with that things where bit better: now if I cancelled input I also received inputMethodEvent with both preedit and commit texts set to empty strings. If I used that as a que to reset the status all seemed work ok. Still, some other non-Qt applications seemed to work better even with mozc so I'm still not sure if there is something Qt should be doing differently here. And I still haven't checked any other platforms.
  • Correct way to interrupt long running calculation inside a slot in another thread?

    Unsolved
    21
    0 Votes
    21 Posts
    3k Views
    Christian EhrlicherC
    You can use your first example, an atomic bool and check this in every n'th iteration. Everything else is not needed and will not help. You can also avoid the atomic bool and use the QThread built-in QThread::requestInterruption() and check for QThread::isInterruptionRequested() once in a while in your loop.
  • Resize QListWidget in scroll area

    Solved
    7
    0 Votes
    7 Posts
    1k Views
    C
    I have finally found a solution, which consists in setting the minimum height of the "QListWidget", equal to: (number or rows + 1) * height of row The final code of the example is (only the last lines have been added): #include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { int numLine, lineHeight; QRect rectItem; // QListWidget objects listWidgetMain = new QListWidget(); listWidgetLineNumbers = new QListWidget(); for (numLine = 0; numLine < 20; numLine++) { listWidgetMain->addItem("text_" + QString::number(numLine + 1)); listWidgetLineNumbers->addItem(QString::number(numLine + 1)); } // Layout with the lists built horizLayoutInScrollArea = new QHBoxLayout(); horizLayoutInScrollArea->addWidget(listWidgetMain); horizLayoutInScrollArea->addWidget(listWidgetLineNumbers); // Scroll area widgetInScrollArea = new QWidget(); widgetInScrollArea->setLayout(horizLayoutInScrollArea); scrollArea = new QScrollArea(); scrollArea->setWidget(widgetInScrollArea); scrollArea->setWidgetResizable(true); // Main layout horizLayoutMain = new QHBoxLayout(); horizLayoutMain->addWidget(scrollArea); // Main widget centralWidget = new QWidget(); setCentralWidget(centralWidget); centralWidget->setLayout(horizLayoutMain); // Setting of the minimum height QListWidgetItem *firstLine; firstLine = listWidgetMain->item(0); rectItem = listWidgetMain->visualItemRect(firstLine); lineHeight = rectItem.height(); listWidgetMain->setMinimumHeight(lineHeight * (listWidgetMain->count() + 1)); }
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    3 Views
    No one has replied
  • QToolButton::focus background

    Unsolved
    1
    0 Votes
    1 Posts
    182 Views
    No one has replied
  • How do I use SVG images in QPushButton style sheets and make them clear in HD mode?

    Unsolved
    1
    0 Votes
    1 Posts
    295 Views
    No one has replied
  • Unable to add a widget to a QScrollArea object dynamically

    Solved
    13
    0 Votes
    13 Posts
    2k Views
    jsulmJ
    @JonB Yes, the emitter sends new widget to add via signal. The receiver adds it to its UI.
  • Fill a MS Word object with multiple data values

    Unsolved
    7
    0 Votes
    7 Posts
    682 Views
    A
    Thank you for your suggestions, they were helpful. I just wanted to update you and in case someone else needs the information that it worked by using bookmarks as solution!
  • Creating and adding values to Chart in Word C++ ActiveQT

    Unsolved
    1
    0 Votes
    1 Posts
    200 Views
    No one has replied
  • How to retranslate the text in QListView with a model

    Solved
    4
    0 Votes
    4 Posts
    312 Views
    J.HilkJ
    @Mihan yes exactly, every text that you set in your cpp or h files you will have to reapply, when the changeEvent LanguageChanged occurs. Only exception are texts that are set by ui files(and not later changed via cpp files)
  • Reloading certain widgets present on stacked widgets after pressing buttons

    Solved
    13
    0 Votes
    13 Posts
    1k Views
    Thank YouT
    @J-Hilk Yes as soon as @jsulm said about filling certain data I used that method I created function which include all the things previously mentioned in constructor and called before setting things. So anyone coming here should do what @jsulm suggested using @J-Hilk method Thank You
  • QtCreator doesn't load .cpp and .h files from CMake project

    Unsolved cmake qtcreator vtk
    4
    0 Votes
    4 Posts
    1k Views
    Please_Help_me_DP
    If possible maybe somebody could clone the repository and try it his computer to open project and run CMake. Not necessary to build the project (it may take 9 hours) but before launching CMake set build dir path as short as possible (I have build folder C:\S\b and the source C:\S\Slicer) because Slicer has some problems with path length and CMake will throw an error if build folder path is too long. I'm very interested in working on this project in QtCreator and not in Visual Studio but that QtCreator's behavior doesn't leave me any chances.
  • Qt's common patterns for collection change signals?

    Unsolved
    12
    0 Votes
    12 Posts
    958 Views
    I
    @Christian-Ehrlicher So are you suggesting class SomeClass: public QObject { ... Q_PROPERTY(QAbstractItemModel* collection ...) ... }; ?
  • Problem With QRect and QPainter

    Solved
    17
    0 Votes
    17 Posts
    2k Views
    SGaistS
    You know the number of entries of your menu bar, so use it for the loop.
  • QtCreator from Linux to Windows 10

    Solved
    7
    0 Votes
    7 Posts
    1k Views
    JonBJ
    @Kezin99 So Qt Creator cannot help you much in this case. It's an IDE/editor like everything else. You have to change to make things work under Windows if you have Linux-specific code. If you are writing your own Qt code, this does not happen, as the Qt libraries/headers abstract away the difference between platforms. Usually you don't write code which includes the headers you mention, you use Qt equivalents instead. If you cannot/do not wish to rewrite to work that way, you will have to find your own platform-specific equivalents. Or, as @Psnarf said, you could find another abstract layer like Posix and rewrite for that.
  • How to drag another Qdockwidget on one Qdockwidget

    Solved
    6
    0 Votes
    6 Posts
    437 Views
    M
    Sory, it is works self.ui.tabifyDockWidget(self.ui.dockWidgetGroupmentsBallistic, self.ui.dockWidgetGroupmentsAc)