Portál AbcLinuxu, 13. května 2025 00:17
Řešení dotazu:
connect(tlacitko_QPushButton, SIGNAL(clicked()), text_QLabel, SLOT(hide()));
connect(tlacitko_QPushButton, SIGNAL(clicked()), text_QLabel, SLOT(show()));
No tak v designeru asi na hide nastavit nejde ale do zdrojáku přesně nevím kam to napsat omlouvám se ale jsem prostě jelito :)
#include <QApplication> #include "widget.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; w.show(); return a.exec(); }widget.h
#ifndef WIDGET_H #define WIDGET_H #include <QWidget> class QLabel; class QPushButton; class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = 0); private: QLabel* label; QPushButton* btn; }; #endif // WIDGET_Hwidget.cpp
#include "widget.h" #include <QtGui> Widget::Widget(QWidget *parent) : QWidget(parent) { label = new QLabel("ahoj!"); label->hide(); btn = new QPushButton("zobrazit"); btn->setCheckable(true); QHBoxLayout* layout = new QHBoxLayout(this); layout->addWidget(btn,5); layout->addWidget(label); connect(btn, SIGNAL(clicked(bool)), label, SLOT(setShown(bool))); // tohle není třeba díky tomu, že při vytváření // layoutu jsme předali this jako parent //this->setLayout(layout); this->setFixedWidth(500); }
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.